package com.googlecode.imule.apps;

/**
 * Controls each item present in system
 * @author Mike Solomon, Owen Phelan
 */

import java.io.IOException;
import java.net.SocketException;
import java.util.Scanner;

import com.apple.dnssd.DNSSDException;

/**
 * Control device
 * 
 * @author Owen Phelan
 */


public class Controller {

	public String name;
	public String type;
	public String com_protocol = "udp";
	public String description;
	public String status;
	
	/* - Create controller interfer
	 * - Flow Layout?
	 * - Cycle through contacts and display image if TYPE is present?
	 * - Return status of objects?
	 * - Clicking on object should send ACTION message to each? 
	 *  */
	
	public static void main(String[] args) throws DNSSDException, IOException{
		String name = "Controller";
		X controller = new X(name);
		Scanner scanner = new Scanner(System.in);
		String input = "";
	
		while (!input.equalsIgnoreCase("close")) {
			input = scanner.nextLine();
			if (input.charAt(0) == '@') {
				String[] split = input.split("\\s");
				String serviceName = split[0].substring(1, split[0].length());
				if (split[1].charAt(0) == '@') {
					controller.sendAction(serviceName);
				} else {
					String message = "";
					for (int i = 1; i < split.length; i++) {
						message += split[i] + " ";
					}
					controller.send(message, serviceName);
				}
			} else {
				controller.broadcast(input);
			}
		}
		System.out.println("closing");
		System.exit(0);
	}
}
